/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bash.carrep.ui;

import com.bash.carrep.dao.enties.CreditLevel;
import com.bash.carrep.dao.general.CRUD;
import com.bash.carrep.ui.datasource.CreditLevelContainer;
import com.bash.carrep.ui.util.CLFieldFactory;
import com.vaadin.ui.Window;
import java.util.Arrays;

/**
 *
 * @author bash
 */
public class CreditLevelForm extends AbstractFrom {

    CreditLevel cl;

    public CreditLevelForm(CarrepApplication app) {
        super(app, CreditLevel.class);
        setFormFieldFactory(new CLFieldFactory());
        cl = (CreditLevel) pojo;

        setItemDataSource(bi);
        // getItemDataSource().removeItemProperty("loginList");
        setVisibleLabels(Arrays.asList(new String[]{"idcreditLevel", "description"}));

        buildButtons();
    }

    @Override
    void initDatasource() {
        form.setItemDataSource(bi);
    }

    @Override
    void buildButtons() {
        standardfooter = new EditSaveCancelView<CreditLevel>(new CreditLevelContainer(), this);
        setFooter(standardfooter);
    }

    @Override
    void submit() {

        CRUD crud = CRUD.getInstance();

        try {
            CreditLevel data =(CreditLevel) pojo;
            crud.start();
            crud.persist(data);
            crud.stop();
            showNotification("Confirmation", Window.Notification.TYPE_HUMANIZED_MESSAGE,
                    Window.Notification.POSITION_CENTERED_TOP, "<b>Effectué avec succès !</b>");
            
            app.showCreditLevelView();

        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
